<?php

namespace app\common\service;

use app\common\model\Region;
use app\http\exception\ApiException;

class RegionService extends BaseService
{
    public static function getRegionPage($data)
    {
        return Region::build()
                     ->orderBy('id', 'desc')
                     ->_paginate();
    }

    public static function getRegionList($data)
    {
        return Region::build()
                     ->equal('parent_id,level,area_id')
                     ->like('area_name')
                     ->orderBy('id', 'desc')
                     ->select();
    }

    public static function getRegionItem($id)
    {
        return Region::build()
                     ->findOrFail($id);
    }

    public static function delRegionItem(Region $Region)
    {
        return $Region->delete();
    }

    public static function setRegionItem(Region $Region, $data)
    {
        $Region->save($data);
        return $Region;
    }


    public static function addRegionItem($data)
    {
        $model = new Region();
        return $model->save($data);
    }


}
